package com.qms.qep.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qms.common.annotation.Log;
import com.qms.common.core.controller.BaseController;
import com.qms.common.core.domain.AjaxResult;
import com.qms.common.core.page.TableDataInfo;
import com.qms.common.enums.BusinessType;
import com.qms.qep.domain.Parameter;
import com.qms.qep.service.IParameterService;

/**
 * 参数管理Controller
 * 
 * @author qms
 */
@RestController
@RequestMapping("/qep/param")
public class ParameterController extends BaseController
{
    @Autowired
    private IParameterService parameterService;

    /**
     * 查询参数列表
     */
    @PreAuthorize("@ss.hasPermi('qep:param:list')")
    @GetMapping("/list")
    public TableDataInfo list(Parameter parameter)
    {
        startPage();
        List<Parameter> list = parameterService.selectParameterList(parameter);
        return getDataTable(list);
    }

    /**
     * 获取参数详细信息
     */
    @PreAuthorize("@ss.hasPermi('qep:param:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(parameterService.selectParameterById(id));
    }

    /**
     * 新增参数
     */
    @PreAuthorize("@ss.hasPermi('qep:param:add')")
    @Log(title = "参数管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Parameter parameter)
    {
        return toAjax(parameterService.insertParameter(parameter));
    }

    /**
     * 修改参数
     */
    @PreAuthorize("@ss.hasPermi('qep:param:edit')")
    @Log(title = "参数管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Parameter parameter)
    {
        return toAjax(parameterService.updateParameter(parameter));
    }

    /**
     * 删除参数
     */
    @PreAuthorize("@ss.hasPermi('qep:param:remove')")
    @Log(title = "参数管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(parameterService.deleteParameterById(id));
    }
    
    /**
     * 根据产品ID获取参数列表
     */
    @GetMapping("/product/{productId}")
    public AjaxResult getParametersByProduct(@PathVariable("productId") Long productId)
    {
        List<Parameter> list = parameterService.selectParametersByProductId(productId);
        return success(list);
    }
    
    /**
     * 获取参数类型选项
     */
    @GetMapping("/typeOptions")
    public AjaxResult getTypeOptions()
    {
        return success(parameterService.getParameterTypeOptions());
    }
} 